﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DTO;

namespace DAO
{

	public class TblTuyenPhatDAO:IData<TblTuyenPhat> 
 	{
		public TblTuyenPhatDAO(String myconnecString) : base(myconnecString) { }

		protected override int InsertOnSubmit(ref TblTuyenPhat item, int t) {
			 return connec.ExecuteNonQuery("sp_TblTuyenPhat", CommandType.StoredProcedure,
                 new SqlParameter("@flag", t),
				 new SqlParameter("@" + TblTuyenPhat.c_MaTuyenPhat, item.MaTuyenPhat),
                 new SqlParameter("@" + TblTuyenPhat.c_TenTuyenPhat, item.TenTuyenPhat),
				 new SqlParameter("@" + TblTuyenPhat.c_DaXoa, item.DaXoa));
		}

		public override TblTuyenPhat GetItem(IDataReader dr)
		{
			TblTuyenPhat obj = new TblTuyenPhat();
			obj.MaTuyenPhat = Convert.ToInt32(dr[TblTuyenPhat.c_MaTuyenPhat]);
			obj.TenTuyenPhat = Convert.ToString(dr[TblTuyenPhat.c_TenTuyenPhat]);
			obj.DaXoa = Convert.ToBoolean(dr[TblTuyenPhat.c_DaXoa]);
			return obj;
		}

		public override List<TblTuyenPhat> GetAll()
		{
			return GetAll("sp_GetAllTblTuyenPhat", CommandType.StoredProcedure);
		}

		public override TblTuyenPhat GetItemById(object id)
		{
			return GetAll().SingleOrDefault(p => p.MaTuyenPhat == Convert.ToInt32(id));
		}
        
		public override TblTuyenPhat GetItemById(TblTuyenPhat item){
			throw new NotImplementedException();
		}
        
	}

 }
